
//处理销售逻辑业务
import 'package:flutter/cupertino.dart';
import 'package:mvvmdemo/common/appglabaldata.dart';
import 'package:mvvmdemo/model/order_model.dart';
import 'package:mvvmdemo/service/parameter_interface.dart';
import 'package:mvvmdemo/viewmodel/state/appmodel.dart';
import 'package:provider/provider.dart';

class SaleViewModel {
  static  SaleViewModel? _saleViewModel;
  static SaleViewModel? getSaleViewModel(){
    _saleViewModel ??= SaleViewModel();
    return _saleViewModel;
   }
  init() async {
    var result = await ParameterInterface.getNetService()!.tradeInit();
    if(null!=result&&result['returncode']=='0'){
      AppGlabalData.flowNo = result['data']['flowNo'];
    }
  }

  findGoods1(BuildContext context)async{
    var result = await ParameterInterface.getNetService()!.findGoods1();
    if(null!=result&&result['returncode']=='0'){
      AppGlabalData.orderModel = OrderModel.fromJson(result);
      AppModel appModel = Provider.of<AppModel>(context, listen: false);
      appModel.updateOrderModel();
    }
  }

  findGoods2(BuildContext context)async{
    var result = await ParameterInterface.getNetService()!.findGoods2();
    if(null!=result&&result['returncode']=='0'){
      AppGlabalData.orderModel = OrderModel.fromJson(result);
      AppModel appModel = Provider.of<AppModel>(context, listen: false);
      appModel.updateOrderModel();
    }
  }

  back(BuildContext context) async {
    Navigator.pushReplacementNamed(context, "/loginpage");
    AppGlabalData.orderModel = null;
    AppModel appModel = Provider.of<AppModel>(context,listen: false);
    appModel.updateOrderModel();

  }
}